// 提交审核
import Vue from 'vue'
import {store} from '@/store/index'
import schema from 'async-validator'
import noticeModal from '@/components/ivew_components/notice_modal/index.vue'
import carValidateList from'@/components/ivew_conf/car_order_validate_list'

import {carValidator, buildErrorNotice} from '@/utils/car_validator.ts'
import commonFn from './common_fn.ts'

let vue:any = new Vue();

const conf = { 

    title:'申请核保',
    icon: 'icon-share',
    pag: 'carSubmitExamine',
    fn (){

        let orderData = store.state['carFormStore']['orderData'];
        let validator:any = new schema(carValidateList);

        // 数据验证 （短路）
        if(!carValidator(orderData)){return}

        // 保存订单数据
        store.dispatch('request', {
            url: 'patch/orders/id',
            data:{}
        }).then(success =>{

            // 修改订单状态
            if(success){
                store.dispatch('request', {
                    url: 'patch/order/id/status',
                    data: {
                        currentAction: '申请核保'
                    }
                }).then(success =>{

                    if(success){

                        vue.$Notice.success({
                            title: '申请成功'
                        })

                        setTimeout(() =>{
                            commonFn('updateTable','outForm')
                        }, 500)
                        
                    }
                    
                })
                
            }else{
                buildErrorNotice('自动保存失败, 请重新提交', '提交失败')
            }
            
        })
        
    }
    
}

export default conf